package com.example.testdatabase;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.SimpleCursorTreeAdapter;

public class database_show_activity extends Activity {
	
	
	ListView list;
	
	SimpleCursorAdapter mAdapter;
	Handler mHandler = new Handler();
	
	Cursor mCursor;
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    
	    setContentView(R.layout.database_show_layout);
	    
	    list = (ListView)findViewById(R.id.listView1);
	    
	    mAdapter = new SimpleCursorAdapter(this, R.layout.item_layout, null, new String[] {DataBaseModel.DataFields.People.NAME, DataBaseModel.DataFields.People.PHONE, DataBaseModel.DataFields.People.ADDRESS, DataBaseModel.DataFields.People.AGE}, 
	    		new int[] {R.id.textView1, R.id.textView2, R.id.textView3, R.id.textView4});
	    list.setAdapter(mAdapter);
	    
	    DataBaseModel.getInstance().getDataList(null, new DataBaseModel.OnQueuryResultListener() {
			
			@Override
			public void onQueuryResult(Cursor c) {
				// TODO Auto-generated method stub
				mAdapter.changeCursor(c);
			}
		}, mHandler);
//	     startManagingCursor(c);
	    
	   
	    // TODO Auto-generated method stub
	    
	   
	}
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		if(mCursor !=null)
		mCursor.close();
		super.onDestroy();
	}

}
